var AlumniModel = Class.extend({
	_alumni : null,

	// injected by the provider
	_alumniService : null,

	search : function(query, successcb, errorcb) {
		return this._alumniService.search(query, successcb, errorcb).then(
				function(data) {
					this._alumni = data;
				}.bind(this));
	},
	advancedSearch : function(conditions, successcb, errorcb) {
		return this._alumniService.advancedSearch(conditions, successcb,
				errorcb).then(function(data) {
			this._alumni = data;
		}.bind(this));
	},
	get : function(id, successcb, errorcb) {
		this._alumniService.get(id, successcb, errorcb).then(function(data) {
			this._alumni = data;
		});
	},
	remove : function(id, sucesscb, errorcb) {
		this._alumniService.remove(id, function() {
			for (var i = 0; i < this._alumni.length; i++) {
				if (this._alumni[i].alumusId == id) {
					this._alumni.splice(i, 1);
					break;
				}
			}

			var scb = sucesscb || angular.noop;

			scb(this._alumni);
		}.bind(this), function() {
			var ecb = errorcb || angular.noop;
			ecb('校友删除错误！');
		});
	},

	updatePersonalInfo : function(personalInfo, successcb, errorcb) {
		this._alumniService
				.updatePersonalInfo(personalInfo, successcb, errorcb).then(
						function(data) {
						}.bind(this));
	},

	updateAlumniInfo : function(postObject, primaryKey, restfulServiceName,
			successcb, errorcb) {
		this._alumniService.updateAlumniInfo(postObject, primaryKey,
				restfulServiceName, successcb, errorcb).then(function(data) {

		}.bind(this));
	},

	createAlumniInfo : function(postObject, restfulServiceName, successcb,
			errorcb) {
		this._alumniService.createAlumniInfo(postObject,
				restfulServiceName, successcb, errorcb).then(function(data) {

		}.bind(this));
	},

	removeAlumniInfo : function(alumusId, primaryKeyId, restfulServiceName,
			successcb, errorcb) {
		this._alumniService.removeAlumniInfo(alumusId,
				primaryKeyId, restfulServiceName, successcb, errorcb).then(function(data) {

		}.bind(this));
	},
	
	updateAssociation : function(association, successcb, errorcb) {
		this._alumniService
		.updateAssociation(association, successcb, errorcb).then(
				function(data) {
				}.bind(this));
	}
});

(function() {

	var AlumniModelProvider = Class.extend({

		instance : new AlumniModel(),

		/**
		 * Initialize and configure AlumniModel
		 * 
		 * @return AlumniModel
		 */
		$get : [ 'AlumniService', function(AlumniService) {
			this.instance._alumniService = AlumniService;
			return this.instance;
		} ]
	})

	angular.module('alumni.AlumniModel', []).provider('AlumniModel',
			AlumniModelProvider);
}());